package com.xiaoshuidi.cloud.module.member.mapper;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaoshuidi.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.xiaoshuidi.cloud.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.xiaoshuidi.cloud.module.member.api.user.dto.MemberUserAuthInfoDTO;
import com.xiaoshuidi.cloud.module.member.enums.UserStateEnum;
import com.xiaoshuidi.cloud.module.member.pojo.user.MemberUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 会员 User Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface MemberUserMapper extends BaseMapperX<MemberUser> {

    default MemberUser selectByMobile(String mobile) {
        List<MemberUser> users = this.selectList(new LambdaQueryWrapper<MemberUser>().eq(MemberUser::getMobile, mobile)
                .eq(MemberUser::getStatus, UserStateEnum.INUSE.getCode()));
        if (users != null && users.size() > 0) {
            return users.get(0);
        }
        return null;
    }

    default List<MemberUser> selectListByNicknameLike(String nickname) {
        return selectList(new LambdaQueryWrapperX<MemberUser>()
                .likeIfPresent(MemberUser::getNickname, nickname));
    }

    MemberUserAuthInfoDTO getUserAuthInfo(@Param("mobile") String moible);

    void deleteOldMoible(@Param("user") MemberUser old);

    void cancelInvalid(@Param("mobile") String mobile);

    MemberUser getUserByMobile(@Param("mobile")String oldMobile);

    @Select("SELECT p.* from member_user p where p.birthday is NOT null and SUBSTR(p.birthday FROM 6 FOR 2)  like CONCAT('%',#{month},'%')")
    List<MemberUser> getUserByBirthdayMonth(@Param("month") String month);
}
